home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 23 / AACD 23.iso / AACD / Online / opennap / topic.c < prev    next >
C/C++ Source or Header  |  2001-06-08  |  3KB  |  116 lines

  1. /* Copyright (C) 2000-1 drscholl@users.sourceforge.net
  2.    This is free software distributed under the terms of the
  3.    GNU Public License.
  4.  
  5.    $Id: topic.c,v 1.28 2001/02/15 08:39:45 drscholl Exp $ */
  6.  
  7. #ifndef WIN32
  8. #include <unistd.h>
  9. #endif
  10. #include <string.h>
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include "opennap.h"
  14. #include "debug.h"
  15.  
  16. /* topic for channel has changed */
  17. /* [ :<nick> ] <channel> [topic] */
  18.  
  19. HANDLER (topic)
  20. {
  21.     CHANNEL *chan;
  22.     int     l;
  23.     char   *chanName, *sender_name, *ptr;
  24.     LIST   *list;
  25.     CHANUSER *chanUser;
  26.     USER   *sender;
  27.  
  28.     (void) len;
  29.     ASSERT (validate_connection (con));
  30.  
  31.     if (pop_user_server (con, tag, &pkt, &sender_name, &sender))
  32.     return;
  33.  
  34.     /* don't use split line because the topic could be multi-word */
  35.     chanName = next_arg (&pkt);
  36.     if (!chanName)
  37.     {
  38.     if (ISUSER (con))
  39.         send_cmd (con, MSG_SERVER_NOSUCH,
  40.               "topic failed: missing channel name");
  41.     return;
  42.     }
  43.  
  44.     chan = hash_lookup (Channels, chanName);
  45.     if (!chan)
  46.     {
  47.     nosuchchannel (con);
  48.     return;
  49.     }
  50.  
  51.     if (chan->local && ISSERVER (con))
  52.     {
  53.     log ("topic: server %s set topic on local channel %s",
  54.          con->host, chan->name);
  55.     return;
  56.     }
  57.  
  58.     if (pkt)
  59.     {
  60.     if (sender && sender->level < LEVEL_MODERATOR)
  61.     {
  62.         if (!list_find (sender->channels, chan))
  63.         {
  64.         if (ISUSER (con))
  65.             send_cmd (con, MSG_SERVER_NOSUCH,
  66.                   "topic failed: you are not on that channel");
  67.         return;
  68.         }
  69.         if (!(chan->flags & ON_CHANNEL_TOPIC)
  70.         && !is_chanop (chan, sender))
  71.         {
  72.         if (ISUSER (con))
  73.             send_cmd (con, MSG_SERVER_NOSUCH,
  74.                   "topic failed: topic is restricted");
  75.         return;
  76.         }
  77.     }
  78.  
  79.     if (chan->topic)
  80.         FREE (chan->topic);
  81.     /* if the topic is too long, truncate it */
  82.     if (Max_Topic > 0 && strlen (pkt) > (unsigned) Max_Topic)
  83.         *(pkt + Max_Topic) = 0;
  84.     if (!(chan->topic = STRDUP (pkt)))
  85.     {
  86.         OUTOFMEMORY ("topic");
  87.         return;
  88.     }
  89.     /* make sure we don't have any wacky characters in the topic */
  90.     for (ptr = chan->topic; *ptr; ptr++)
  91.         if (*ptr == '\r' || *ptr == '\n')
  92.         *ptr = ' ';
  93.     /* relay to peer servers */
  94.     if (!chan->local)
  95.         pass_message_args (con, tag, ":%s %s %s", sender_name, chan->name,
  96.                    chan->topic);
  97.  
  98.     l = form_message (Buf, sizeof (Buf), tag, "%s %s", chan->name,
  99.               chan->topic);
  100.     for (list = chan->users; list; list = list->next)
  101.     {
  102.         chanUser = list->data;
  103.         ASSERT (chanUser->magic == MAGIC_CHANUSER);
  104.         if (chanUser->user->local)
  105.         queue_data (chanUser->user->con, Buf, l);
  106.     }
  107.     notify_ops (chan, "%s set topic on %s: %s", sender_name,
  108.             chan->name, chan->topic);
  109.     }
  110.     else if (ISUSER (con))
  111.     {
  112.     /* return the current topic */
  113.     send_cmd (con, tag, "%s %s", chan->name, chan->topic);
  114.     }
  115. }
  116.